/*
 *  暴力枚举题目
 * */

#include <iostream>
using namespace std;
int main()
{
  // 请在此输入您的代码

  int n;
  cin >> n;

  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    int x = i;
    while (x) {
      int value = x % 10;
      x /= 10;
      if (value == 0 || value == 1 || value == 2 || value == 9) {
        ans += i;
        break;
      }
    }
  }

  cout << ans;

  return 0;
}